<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/6
 * Time: 15:39
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class ImageController
 * @package app\admin\controller
 * 一合家事图片管理模块
 */
class ImageController extends AdminBaseController
{

    protected  $arrWhere = [];
    /**
     * @return \think\response\View
     * @throws \think\exception\DbException
     * 图片列表
     */
    public function image_list()
    {
        $type = request()->param('type');
        if(!empty($type)){
            $this->arrWhere['type'] = $type;
        }
        $list = Db::name('image')->where('status',1)->where($this->arrWhere)->paginate(8);
        $list->appends(['type'=>$type]);

        $page = $list->render();

        return view('',['list'=>$list,'page'=>$page,'type'=>$type]);
    }


    /**
     * @return \think\response\View
     * 图片添加
     */
    public function add_image()
    {
        if(request()->isPost()){
            $data = request()->param();
            $data['create_time'] = time();
            $res = Db::name('image')->insert($data);
            if($res){
                $this->success('添加成功!', url('image/image_list'));
            }else{
                $this->error('添加成功！',url('image/image_list'));
            }
        }

        return view();
    }

    public function image_del()
    {
        $id = $this->request->param('id', 0, 'intval');
        if (Db::name('image')->delete($id) !== false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
}